-- Force
-- 施加力的类型
Force = {}
function Force.calcGravity(world,body)
    local force = vec2(0,0)
    local v1,v2 = vec2(body.x,body.y)
    for k,v in pairs(world.objects) do
        if body ~= v and v.type == DYNAMIC then
            v2 = vec2(v.x,v.y)
            force = force + (v2 - v1) / v1:distSqr(v2) * body.mass * v.mass
        end
    end
    return force
end

function Force.calcAttractiveForce(world,body)
    local force = vec2(0,0)
    local v1,v2 = vec2(body.x,body.y)
    for k,v in pairs(world.objects) do
        if body ~= v and v.type == DYNAMIC then
            v2 = vec2(v.x,v.y)
            force = force + (v2 - v1) / v1:dist(v2) * body.mass * v.mass
        end
    end
    return force
end

function Force.calcExplode(world,body,position,radius,strenth)
    local force = vec2(0,0)
    local bodyPos = vec2(body.x,body.y)
    if position:dist(bodyPos) < radius then
        force = (bodyPos - position):normalize() * strenth-- * (radius / position:dist(bodyPos))
    end
    return force
end
